<!-- 安全评价报告网上信息公开库详情展示 -->
<template>
    <div>
        <!-- 项目概况 -->
        <div class="basic">
            <div class="header">
                <div class="title">
                    <span>项目概况</span>
                </div>
            </div>
            <div>
                <div class="one">
                    <div class="first">
                        <span class="name">项目名称：</span>
                        <span v-if="editor">{{ safety.projectName }}</span>
                        <span><el-input v-if="!editor" v-model="safety.projectName" clearable /></span>
                    </div>
                </div>
                <div class="one">
                    <div class="first">
                        <span class="name">项目地址：</span>
                        <span v-if="editor">{{ safety.projectAddress }}</span>
                        <span><el-input v-if="!editor" v-model="safety.projectAddress" clearable /></span>
                    </div>
                </div>
                <div class="one">
                    <div class="first">
                        <span class="name">项目所属行业：</span>
                        <span v-if="editor">{{ safety.projectIndustry }}</span>
                        <span><el-input v-if="!editor" v-model="safety.projectIndustry" clearable /></span>
                    </div>
                </div>
                <div class="one">
                    <div class="first">
                        <span class="name">评价类型：</span>
                        <span v-if="editor">{{ safety.evaluateType }}</span>
                        <span><el-input v-if="!editor" v-model="safety.evaluateType" clearable /></span>
                    </div>
                </div>
                <div class="one">
                    <div class="first">
                        <span class="name">项目简介：</span>
                        <span v-if="editor"><el-input v-model="safety.projectDesc" type="textarea" style="width: 300px;" readonly /></span>
                        <span><el-input v-if="!editor" v-model="safety.projectDesc" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" style="width: 300px;" placeholder="请输入内容" /></span>
                    </div>
                </div>
            </div>
        </div>
        <!-- 评价机构情况 -->
        <div class="basic">
            <div class="header">
                <div class="title">
                    <span>评价机构情况</span>
                </div>
            </div>
            <div>
                <div class="one">
                    <div class="first">
                        <span class="name">评价机构：</span>
                        <span v-if="editor">{{ safety.evaluateAgent }}</span>
                        <span><el-input v-if="!editor" v-model="safety.evaluateAgent" clearable /></span>
                    </div>
                </div>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <div class="one">
                            <div class="first">
                                <span class="name">机构资质证书号：</span>
                                <span v-if="editor">{{ safety.agentQualifiCertificate }}</span>
                                <span><el-input v-if="!editor" v-model="safety.agentQualifiCertificate" clearable /></span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="one">
                            <div class="first">
                                <span class="name">资质有效期：</span>
                                <span v-if="editor">{{ safety.qualifiCertificateEffectTime }}</span>
                                <el-date-picker v-if="!editor" v-model="safety.qualifiCertificateEffectTime" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期" clearable />
                            </div>
                        </div>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <div class="one">
                            <div class="first">
                                <span class="name">技术负责人：</span>
                                <span v-if="editor">{{ safety.techCharger }}</span>
                                <span><el-input v-if="!editor" v-model="safety.techCharger" clearable /></span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="one">
                            <div class="first">
                                <span class="name">过程控制负责人：</span>
                                <span v-if="editor">{{ safety.processControl }}</span>
                                <span><el-input v-if="!editor" v-model="safety.processControl" clearable /></span>
                            </div>
                        </div>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <div class="one">
                            <div class="first">
                                <span class="name">报告编制人：</span>
                                <span v-if="editor">{{ safety.reporter }}</span>
                                <span><el-input v-if="!editor" v-model="safety.reporter" clearable /></span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="one">
                            <div class="first">
                                <span class="name">报告审核人：</span>
                                <span v-if="editor">{{ safety.reportExamine }}</span>
                                <span><el-input v-if="!editor" v-model="safety.reportExamine" clearable /></span>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </div>
        <!-- 项目组情况 -->
        <div class="basic">
            <div class="header">
                <div class="title">
                    <span>项目组情况</span>
                    <span><el-button style="margin-left: 10px;" type="success" plain size="mini" @click="showAddMember">添加</el-button></span>
                </div>
            </div>
            <div style="padding: 5px;">
                <el-table border stripe :data="AssessReportTeam" style="width: 70%; margin-left: 40px; padding-bottom: 15px;">
                    <el-table-column prop="peopleName" align="center" label="成员姓名" width="90" />
                    <el-table-column prop="vocaQualifiNum" align="center" label="职业资格证书号" width="200" />
                    <el-table-column prop="peopleMajor" align="center" label="专业" width="200" />
                    <el-table-column prop="peopleAttribute" align="center" label="成员类型" />
                    <el-table-column label="操作" align="center" width="200">
                        <template slot-scope="scope">
                            <el-button type="primary" plain size="mini" @click="editMembers(scope.row)">编辑</el-button>
                            <el-button type="danger" size="mini" @click="deleteMembers(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
        <!-- 评价现场情况 -->
        <div class="basic">
            <div class="header">
                <div class="title">
                    <span>评价现场</span>
                </div>
            </div>
            <div class="one">
                <div class="first">
                    <span class="name">现场勘验人员：</span>
                    <span v-if="editor">{{ safety.siteInspectionCharger }}</span>
                    <span><el-input v-if="!editor" v-model="safety.siteInspectionCharger" clearable /></span>
                </div>
            </div>
            <div class="one">
                <div class="first">
                    <span class="name">现场勘验时间：</span>
                    <span v-if="editor">{{ safety.siteInspectionTime }}</span>
                    <el-date-picker v-if="!editor" v-model="safety.siteInspectionTime" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期" clearable />
                </div>
            </div>
            <!--            <div class="one">-->
            <!--                <div class="first">-->
            <!--                    <span class="name">现场勘验图像：</span>-->
            <!--                    <span v-if="editor">{{ safety.zipCode }}</span>-->
            <!--                    <span><el-input v-if="!editor" v-model="safety.zipCode" clearable /></span>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="one">
                <div class="first">
                    <span class="name">评价结论：</span>
                    <span v-if="editor">{{ safety.evaluateConclusion }}</span>
                    <span><el-input v-if="!editor" v-model="safety.evaluateConclusion" clearable /></span>
                </div>
            </div>
        </div>
        <!-- 审批结果 -->
        <div class="basic">
            <div class="header">
                <div class="title">
                    <span>审批结果</span>
                </div>
            </div>
            <div class="one">
                <div class="first">
                    <span class="name">审批部门：</span>
                    <span v-if="editor">{{ safety.apporvalDept }}</span>
                    <span><el-input v-if="!editor" v-model="safety.apporvalDept" clearable /></span>
                </div>
            </div>
            <div class="one">
                <div class="first">
                    <span class="name">审批通过时间：</span>
                    <span v-if="editor">{{ safety.approvalTime }}</span>
                    <el-date-picker v-if="!editor" v-model="safety.approvalTime" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期" clearable />
                </div>
            </div>
        </div>
        <div style="text-align: center;">
            <el-button v-if="editor" type="primary" @click="update">编 辑</el-button>
            <el-button v-if="!editor" type="warning" @click="save">保 存</el-button>
            <el-button v-if="!editor" plain type="primary" @click="cancel">取 消</el-button>
            <div style="margin-left: 10px; display: inline-block;">
                <router-link :to="{name: 'SafetyAssessmentReportInformationIndex'}">
                    <el-button v-if="editor" plain type="primary">返回</el-button>
                </router-link>
            </div>
        </div>
        <!-- 添加项目组成员弹框 -->
        <el-dialog title="添加项目组成员" :visible.sync="dialogVisible1" width="30%" center>
            <el-form ref="addForm" :model="Members" :rules="rules">
                <el-row class="tag">
                    <el-col :span="24">
                        <el-form-item label="成员姓名:" prop="peopleName">
                            <el-input v-model="Members.peopleName" prefix-icon="el-icon-edit" placeholder="请输入姓名" clearable style="width: 250px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="tag">
                    <el-col :span="24">
                        <el-form-item label="职业资格证书号:" prop="vocaQualifiNum">
                            <el-input v-model="Members.vocaQualifiNum" prefix-icon="el-icon-edit" placeholder="请输入职业资格证书号" clearable style="width: 250px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="tag">
                    <el-col :span="24">
                        <el-form-item label="专业:" prop="peopleMajor">
                            <el-input v-model="Members.peopleMajor" prefix-icon="el-icon-edit" placeholder="请输入专业" clearable style="width: 200px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="tag">
                    <el-col :span="24">
                        <el-form-item label="成员类型:" prop="peopleAttribute">
                            <el-select v-model="Members.peopleAttribute" placeholder="请选择成员类型" clearable style="width: 200px;">
                                <el-option v-for="item in memberType" :key="item.value" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible1 = false">取 消</el-button>
                <el-button type="primary" @click="doAddMembers">确 认 添 加</el-button>
            </span>
        </el-dialog>
        <!-- 编辑项目组情况弹框 -->
        <el-dialog title="编辑项目组成员信息" :visible.sync="dialogVisible" width="30%" center>
            <div class="tag">
                <el-tag>成员姓名</el-tag>
                <el-input v-model="edit.peopleName" placeholder="请输入姓名" clearable class="updateProfGroup" />
            </div>
            <div class="tag">
                <el-tag>职业资格证书号</el-tag>
                <el-input v-model.trim="edit.vocaQualifiNum" placeholder="请输入职业资格证书号" clearable class="updateProfGroup" @input="change($event)" />
            </div>
            <div class="tag">
                <el-tag>专业</el-tag>
                <el-input v-model.trim="edit.peopleMajor" placeholder="请输入专业" clearable class="updateProfGroup" @input="change($event)" />
            </div>
            <div class="tag">
                <el-tag>成员类型</el-tag>
                <el-select v-model.trim="edit.peopleAttribute" placeholder="请选择成员类型" clearable class="updateProfGroup" @input="change($event)">
                    <el-option v-for="item in memberType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </div>
            <span slot="footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="savaEdit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {Message} from 'element-ui'

export default {
    name: 'SafetyAssessmentReportInformationDetail',
    data() {
        return {
            safety: {},
            editor: true,
            AssessReportTeam: [],
            projectId: '',
            dialogVisible1: false,
            dialogVisible: false,
            Members: {},
            memberType: [{
                value: '组长',
                label: '组长'
            }, {
                value: '组员',
                label: '组员'
            }],
            rules: {
                peopleName: [
                    { required: true, trigger: 'blur', message: '请输入姓名' }
                ],
                vocaQualifiNum: [
                    { required: true, trigger: 'blur', message: '请输入职业资格证书号' }
                ],
                peopleMajor: [
                    { required: true, trigger: 'blur', message: '请输入专业' }
                ],
                peopleAttribute: [
                    { required: true, trigger: 'change', message: '请选择成员类型' }
                ]
            },
            edit: {}
        }
    },
    created() {
        this.initSafety()
        this.projectId = parseInt(this.$route.query.id)
        this.Members.projectId = parseInt(this.$route.query.id)
        this.initAssessReportTeam()
    },
    methods: {
        initSafety() { // 分页获取安全评价报告信息
            var obj = {page: 1, size: 2, projectName: this.$route.query.projectName, assessAgentName: this.$route.query.assessAgentName}
            this.getRequest('/system/safeAssessReport/getSafeAssessReport', obj).then(resp => {
                if (resp) {
                    this.safety = resp.data.data[0]
                }
            })
        },
        deleteMembers(data) { // 删除一个’项目组成员‘
            this.$confirm('此操作将永久删除  ' + data.peopleName + ',是否继续？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.deleteRequest('/system/safeAssessReport/deleteSafeAssessReportTeam/', data.id).then(resp => {
                    if (resp) {
                        Message.success('删除成功')
                        this.initAssessReportTeam()
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
        },
        doAddMembers() { // 添加’项目组成员‘确认按钮绑定事件
            this.$refs['addForm'].validate(valid => {
                if (valid) {
                    this.postRequest('/system/safeAssessReport/addSafeAssessReportTeam', this.Members).then(resp => {
                        if (resp) {
                            this.dialogVisible1 = false
                            Message.success('添加成功')
                            this.initAssessReportTeam()
                        }
                    })
                }
            })
        },
        initAssessReportTeam() { // 初始获取’项目组成员‘信息
            this.getRequest('/system/safeAssessReport/getSafeAssessReportTeam/' + this.projectId).then(resp => {
                if (resp) {
                    this.AssessReportTeam = resp.data
                }
            })
        },
        showAddMember() { // 添加‘项目组成员’按钮绑定弹窗事件
            this.dialogVisible1 = true
        },
        editMembers(row) { // 编辑安全评价师
            this.edit = row
            this.dialogVisible = true
        },
        change() {
            this.$forceUpdate()
        },
        savaEdit() { // 确认保存编辑的成员信息
            this.putRequest('/system/safeAssessReport/updateSafeAssessReportTeam', this.edit).then(resp => {
                if (resp) {
                    this.dialogVisible = false
                    Message.success('更新成功')
                    this.initAssessReportTeam()
                }
            })
        },
        update() {
            this.editor = false
        },
        cancel() {
            this.editor = true
        },
        save() { // 确认保存整个页面修改信息
            this.editor = !this.editor
            this.putRequest('/system/safeAssessReport/updateSafeAssessReport', this.safety).then(resp => {
                if (resp) {
                    Message.success('更新成功')
                    this.initAssessReportTeam()
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.basic {
    margin: 20px;
    background: #fff;
}
.header {
    padding-top: 15px;
    padding-bottom: 15px;
}
.name {
    color: #888;
    overflow: hidden;
    white-space: nowrap;
    font-size: 16px;
}
.title {
    margin-left: 20px;
    color: #337ab7;
}
.mt {
    border-collapse: collapse;
    margin-left: 20px;
}
.first {
    display: flex;
    margin-left: 40px;
    margin-bottom: 25px;
    align-items: center;
}
.one {
    display: flex !important;
}
.updateProfGroup {
    width: 200px;
    margin-left: 8px;
}
.tag {
    margin-top: 20px;
    margin-left: 30px;
}
</style>
